/***
 * Modify the URL to point to the direct video URL.
 *
 * @param {string} url - The URL to modify.
 * @returns {string} - The modified URL.
 */
function modifyUrl(url) {
  const datePattern = /web\/(\d+?)\//;
  const match = url.match(datePattern);

  if (match) {
    const date = match[1];
    return url.replace(datePattern, `web/${date}if_/`);
  }

  return url;
}

chrome.storage.local.get("redirectToVideo", (result) => {
  if (!result.redirectToVideo) return;

  const metaTag = document.querySelector('meta[property="og:video"]');
  if (metaTag === null) return;

  window.location = modifyUrl(metaTag.getAttribute("content"));
});
